package cn.tedu;

import java.sql.*;

/**
 * @Classname: Demo03
 * @Author: bromide
 * @CreateTime: 2022/5/9--16:26
 * @Version: V1.0
 * @Description:
 */
public class Demo03 {
    public static void main(String[] args) throws SQLException {
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai","root","root");
        Statement s = conn.createStatement();
        //执行插入数据SQL
//        s.executeUpdate("insert into emp(name) values('tom')");
        //执行修改数据SQL
//        s.executeUpdate("update emp set name='jerry' where name='tom'");
        //执行删除数据SQL
//        s.executeUpdate("delete from emp where name='tom'");
        //执行查询的SQL
        ResultSet set = s.executeQuery("select name,sal from emp");
        //遍历结果集中的数据
        while (set.next()){
            //获取游标指向的这条数据的某个字段的值,通过字段名获取
            String name = set.getString(1);
            int sal = set.getInt(2);
            System.out.println(name+":"+sal);
        }
        System.out.println("执行完成!");
        conn.close();
    }
}
